<template>
  <main class="main">
    <div ref="currentScene" class="home">
      <!-- 飞船向前飞位置 -->
      <div class="spacecraft_left_position">
        <img class="spacecraft-img animation_left_fly_until_it_disappears" src="@/assets/images/starfighter.png"
          alt="">
      </div>
      <div class="spacecraft_right_position">
        <img class="spacecraft-img animation_right_fly_until_it_disappears" src="@/assets/images/spacecraft.png" alt="">
      </div>
      <!-- 飞船Idle -->
      <div class="spacecraft_container">
        <img class="spacecraft-img"
          :class="{ 'animation_idle': !isStart, 'animation_fly_until_it_disappears': isStart }"
          src="@/assets/images/spacecraft.png" alt="">
      </div>

      <!-- 欢迎语 -->
      <div class="showText animation_showText" :class="{ 'animation_showText_close': isStart }">
        <div class="brand_or_logo">Vast Universe</div>
        <div class="text">从此刻开始，探索「技术」的无限可能</div>
        <button v-show="!isStart" class="start-btn" @click="start">开始探索</button>
      </div>

    </div>
    <div ref="nextScene" class="content1 hidden">
      <select-component></select-component>
    </div>
    <div class="content2"></div>
  </main>
</template>

<script>
import SelectComponent from '@/components/universe/SelectComponent.vue';
export default {
  data() {
    return {
      isStart: false
    }
  },
  components:{
    SelectComponent,

  },
  methods: {
    start() {
      this.isStart = true;
      this.transitionToNextScene();
    },
    transitionToNextScene() {
        //等待5秒飞船飞到目标位置，然后开始切换场景
        setTimeout(() => {
          this.$refs.currentScene.classList.add('fade-out');
        }, 5000); // 5秒后开始fade-out动画
        setTimeout(() => {
          this.$refs.nextScene.classList.remove('hidden');
          this.$refs.nextScene.classList.add('fade-in');
        }, 8000); // 8秒后开始fade-in动画
      }
  }

}
</script>

<style>
.main {
  display: flex;
  /* 全页默认文字颜色 */
  color: white;
  font-family: "b", "a", sans-serif;
  /* 字体设置 */
}

.home {
  /* 对子元素进行弹性布局 */
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  /*当子元素超出容器尺寸时，会被隐藏起来。解决屏幕下方出现滑动条问题*/
  /*基础设置 */
  width: 100%;
  height: 999px;
  /* 高度基于背景图高度设置 */
  position: relative;
  /* 相对定位 */
  top: 0;

  /* 背景为图片的属性 */
  /* 星空图地址，1440x 代表2k分辨率，可变 2160x 4320x 
    background-image: url(https://cia.hyperos.mi.com/hyperos-homepage/idx_pad.png?imageMogr2/thumbnail/1440x/quality/80/format/webp);

    background-image: url(https://cia.hyperos.mi.com/hyperos-homepage/idx_pc.png?imageMogr2/thumbnail/1440x/quality/80/format/webp); 

    background-image: url(https://cia.hyperos.mi.com/hyperos-homepage/index_page_mob.png?imageMogr2/thumbnail/1440x/quality/80/format/webp);*/


  /* background-image: url(@/assets/images/idx_pc_7680x.webp); */
  background-repeat: no-repeat;
  /* 只显示一次，不在任何方向重复 */
  /* background-size: cover;    保持图像纵横比例，缩放到足够大，使背景图像可以完全覆盖元素所在区域，可以会导致超出部分无法显示，使得图片看起来不完整，被放大，精细度下降 */
  background-size: contain;
  /* 保持图像纵横比例，缩放到足够大，使背景图像可以完整的显示在元素所在区域，可能无法完全覆盖整个元素区域，其他区域需要底色配合，但精细度保持最高*/
  background-color: #000000;
  /* 背景颜色 配合上面contain无法覆盖的部分 */
  background-position: center top;
  /* 背景图片位置 */
  /* background-attachment: fixed;  滚动时，背景图片固定不动 */
  background-attachment: scroll;
  /* 默认值随着页面元素的滚动而移动 */
  transition: opacity 2s ease;
  /* 页面切换时的过渡效果 */
}

.showText {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.brand_or_logo {
  font-size: 3rem;
  font-weight: bold;
}

.text {
  font-size: 1rem;
  margin-bottom: 1rem;
  opacity: 0.8;
}

.start-btn {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 0.5rem;
  background-color: #007aff;
  color: white;
  font-size: 1.2rem;
  cursor: pointer;
}

.start-btn:hover {
  background-color: #0057b7;
}

.content1 {
  width: 100%;
  height: 100%;
  background-color: #000000;
  color: #ffffff;
  position: absolute;
  /* top: 1000px; */
  top: 3rem;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}


.spacecraft-img {
  width: 100%;
  height: 100%;

}

/* 中间飞船的动画效果 */
.animation_fly_until_it_disappears {
  animation: fly_until_it_disappears-animation 10s ease-in-out forwards;
  transform-origin: top left;
  /* 定义飞船最终停留的位置-缩放的基点 */
}

@keyframes fly_until_it_disappears-animation {
  0% {
    transform: scale(1) translateX(0) translateY(0) rotate(0deg);
    opacity: 1;
  }

  50% {
    transform: scale(0.01) translateX(30rem) translateY(30rem) rotate(0deg);
    opacity: 1;
  }

  100% {
    transform: scale(0) translateX(0) translateY(0) rotate(0deg);
    opacity: 1;
  }
}

/* 左边飞船动画效果 */
.animation_left_fly_until_it_disappears {
  animation: left_fly_until_it_disappears-animation 10s ease-in-out infinite;
  transform-origin: center center;
}

@keyframes left_fly_until_it_disappears-animation {
  0% {
    transform: scale(1) translateX(-70rem) translateY(0) rotate(0deg);
    opacity: 1;
  }

  50% {
    transform: scale(0.01) translateX(-58rem) translateY(58rem) rotate(0deg);
    opacity: 1;
  }

  100% {
    transform: scale(0) translateX(0) translateY(0) rotate(0deg);
    opacity: 1;
  }
}

/* 右边飞船动画效果 */
.animation_right_fly_until_it_disappears {
  animation: right_fly_until_it_disappears-animation 15s ease-in-out infinite;
  transform-origin: center center;
}

@keyframes right_fly_until_it_disappears-animation {
  0% {
    transform: scale(1) translateX(65rem) translateY(0) rotate(0deg);
    opacity: 1;
  }

  50% {
    transform: scale(0.01) translateX(58rem) translateY(58rem) rotate(0deg);
    opacity: 1;
  }

  100% {
    transform: scale(0) translateX(0) translateY(0) rotate(0deg);
    opacity: 1;
  }
}

/* 飞船Idle动画效果 */
.animation_idle {
  animation: idle-animation 10s ease-in-out infinite;
  transform-origin: center bottom;
  /* 定义旋转或缩放的基点 */
}

@keyframes idle-animation {

  0%,
  100% {
    transform: translate(0, 0);
    /* 动画开始和结束时，飞船位置不变 */
  }

  25% {
    transform: translate(-10px, -10px);
    /* 飞船向左移动10像素，并轻微上浮 */
  }

  50% {
    transform: translate(20px, -10px);
    /* 飞船向右移动20像素，并轻微上浮 */
  }

  75% {
    transform: translate(-10px, -30px);
    /* 飞船向左移动30像素，并轻微上浮 */
  }
}



/* 文字动画效果 */
.animation_showText {
  animation: showText-animation 1s ease-in-out forwards;
}

@keyframes showText-animation {
  0% {
    opacity: 0;
    transform: translateY(10px);
  }

  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 文字关闭状态的动画 */
.animation_showText_close {
  animation: showTextLeave 1.5s ease-in forwards;
}

@keyframes showTextLeave {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }

  to {
    opacity: 0;
    transform: translateY(-50px) scale(7);
  }
}
/* 切换场景的动画效果 */
.hidden {
  display: none;
}

.fade-out {
  opacity: 0;
}

.fade-in {
  opacity: 1;
}

/* 手机设备 */
@media (max-width: 767px) {
  .home {
    background-image: url(@/assets/images/index_page_mob_1440x.webp);
    /* background-image: url(https://cia.hyperos.mi.com/hyperos-homepage/index_page_mob.png?imageMogr2/thumbnail/1440x/quality/80/format/webp); */
    background-size: cover;
    /* 手机时使用cover，保证图片完整显示，效果更好 */
    background-position: center top;
    height: 100vh;
  }

  .showText {
    position: absolute;
    top: 95vw;
  }
  
  .spacecraft_container {
    width: 20rem;
    height: 20rem;
    position: absolute;
    top: 58vw;
    left: 50%;
  }

  .spacecraft_left_position {
    width: 20rem;
    height: 20rem;
    position: absolute;
    top: 58vw;
    left: 50%;
    transform: translate(-50%, -50%);

  }

  .spacecraft_right_position {
    width: 20rem;
    height: 20rem;
    position: absolute;
    top: 58vw;
    left: 50%;
    transform: translate(-50%, -50%);

  }
}

/* 平板设备 */
@media (min-width: 768px) and (max-width: 1023px) {
  .home {
    background-image: url(@/assets/images/idx_pad_1440x.webp);
    /* background-image: url(https://cia.hyperos.mi.com/hyperos-homepage/idx_pad.png?imageMogr2/thumbnail/1440x/quality/80/format/webp); */
    background-size: cover;
    background-position: center top;
  }

  .showText {
    position: absolute;
    top: 70%;
  }

  .spacecraft_container {
    width: 30rem;
    height: 30rem;
    position: absolute;
    top: 49vw;
    left: 50%;
  }

  .spacecraft_left_position {
    width: 20rem;
    height: 20rem;
    position: absolute;
    top: 49vw;
    left: 50%;
    transform: translate(-50%, -50%);

  }

  .spacecraft_right_position {
    width: 20rem;
    height: 20rem;
    position: absolute;
    top: 49vw;
    left: 50%;
    transform: translate(-50%, -50%);

  }
}


/* pc设备 */
@media (min-width: 1024px) {
  .home {
    background-image: url(@/assets/images/idx_pc_1440x.webp);
    /* background-image: url(https://cia.hyperos.mi.com/hyperos-homepage/idx_pc.png?imageMogr2/thumbnail/3840x/quality/80/format/webp);  */
    background-repeat: no-repeat;
    background-size: contain;
    background-color: #000000;
    background-position: center top;
  }

  .spacecraft_container {
    width: 30rem;
    height: 30rem;
    position: absolute;
    top: 8vw;
    left: 50%;
  }

  .spacecraft_left_position {
    width: 20rem;
    height: 20rem;
    position: absolute;
    top: 8vw;
    left: 50%;
    transform: translate(-50%, -50%);

  }

  .spacecraft_right_position {
    width: 20rem;
    height: 20rem;
    position: absolute;
    top: 8vw;
    left: 50%;
    transform: translate(-50%, -50%);

  }
}
</style>
